package com.victor.dao;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.victor.entity.JMInfo;
import com.victor.entity.step.Schedule;
import com.victor.entity.step.Step;
import com.victor.entity.step.StepDetails;

@Mapper
public interface StepDao {

	/**
	 * 查询现有的流程
	 * 
	 * @return
	 */
	List<Step> getAllStep();

	/**
	 * 创建模板信息
	 * 
	 * @param step
	 * @return
	 */
	int buildStep(Step step);

	/**
	 * 创建模板流程
	 * 
	 * @param stepDetails
	 * @return
	 */
	@Insert({ "insert into jm_step_details (s_id,empid,position) values (#{s_id},#{empid},#{position})" })
	int addStepDetails(StepDetails stepDetails);

	/**
	 * 批量删除流程
	 * 
	 * @param s_ids
	 * @return
	 */
	int batchDeleteStep(@Param("ids") int[] ids);
	
	/**
	 * 	该模板下流程详细表
	 * @param s_id 模板id
	 * @return
	 */
	@Select({"select * from jm_step_details where s_id=#{s_id}"})
	List<StepDetails> getStepDetailsByS_id(Integer s_id);

	/**
	 * 分配应用模板
	 * @param schedule
	 * @return
	 */
	boolean allotStep(Schedule schedule);

	/**
	 * 	分配模板成功修改加盟实体类状态1
	 * @param schedule
	 * @return
	 */
	@Update({"update jm_info set status='1' where id=#{id}"})
	boolean updateStatus(Integer id);

	/**
	 * 	查询待我审批
	 * @param empid    登录员工的id 
	 * @return
	 */
	@Select({"select * from jm_schedule where sp_empid=#{empid} and personal_status='2' "})
	List<Schedule> selfSPById(String empid);
	
	/**
	 * 查询加盟实体类
	 * @param id
	 * @return
	 */
	@Select({"select id,date,msshopname,bghotelname,jqgsname,"
			+ "msshopclass,bghotelclass,jqcompanyclass,"
			+ "msaddress,bgaddress,jqdetailaddress,"
			+ "status from jm_info where id=#{id}"})
	JMInfo getInfoById(int id);

	/**
	 * 	查询 (我参与的审批 )
	 * @param empid    登录员工的id 
	 * @return
	 */
	@Select({"select * from jm_schedule where sp_empid=#{empid} "})
	List<Schedule> selfSPJoinById(String empid);
	
	/**
	 *	通过审批 
	 * @return
	 */
	@Update({" update jm_schedule set personal_status='3',sp_time=now() where id=#{id}  "})
	boolean pass(Integer id);
	
	/**
	 *	 查询下一审批进程
	 * @param sp_sequence
	 * @param info_id
	 * @return
	 */
	@Select({" select id from jm_schedule where info_id=#{info_id} and sp_sequence=#{sp_sequence}"})
	Integer selectIdBySpsequence(String sp_sequence, String info_id);
	
	/**
	 * 审批通过修改下流程状态
	 * @return
	 */
	@Update({" update jm_schedule set personal_status='2' where id=#{id}"})
	boolean updateNextPersonStatus(Integer id);

	/**
	 * 	拒绝审批
	 * @param id 审核进度id
	 * @param messageString 拒绝信息
	 * @return
	 */
	@Update({" update jm_schedule set personal_status='4',sp_time=now(),not_pass_reason=#{not_pass_reason} where id = #{id}"})
	boolean no(Integer id,String not_pass_reason);

	/**
	 * 	拒绝审批，修改加盟实体类状态4
	 * @param id
	 * @return
	 */
	@Update({" update jm_info set status='4' where id=#{id}"})
	boolean noPassJminfo(Integer id);

	/**
	 * 最后一个审批人就修改加盟实体类的状态2
	 * @param id
	 * @return
	 */
	@Update({" update jm_info set status='2' where id=#{id}"})
	boolean updateJMinfoById(Integer id);
	
	/**
	 *	 根据id	查询模板列表
	 * @param ids
	 * @return
	 */
	List<Step> getStepList(int[] ids);
	
//	/**
//	 * 查询待我审批 empid 登录员工的id 即员工adminid
//	 * 
//	 * @param empid
//	 * @return
//	 */
//	List<JMInfo> needMeStep(@Param("empid") String empid);
//
//	/**
//	 * 查询我参与的审批
//	 * 
//	 * @param empid
//	 * @return
//	 */
//	List<JMInfo> joinMeStep(@Param("empid") String empid);

}
